import { NextRequest, NextResponse } from 'next/server';

export async function POST(request: NextRequest) {
    try {
        const { password } = await request.json();

        if (!password) {
            return NextResponse.json(
                { success: false, error: '密码不能为空' },
                { status: 400 }
            );
        }

        // 从环境变量获取管理密码
        const managementPassword = process.env.MANAGEMENT_PASSWORD || 'admin123';

        if (password === managementPassword) {
            return NextResponse.json({
                success: true,
                message: '密码验证成功'
            });
        } else {
            return NextResponse.json(
                { success: false, error: '密码错误' },
                { status: 401 }
            );
        }
    } catch (error) {
        console.error('Error verifying password:', error);
        return NextResponse.json(
            { success: false, error: '密码验证失败' },
            { status: 500 }
        );
    }
}
